package com.finer.service.impl;

import com.finer.entity.buy.SupplierPriceGoods;
import com.finer.dao.SupplierPriceGoodsDao;
import com.finer.service.SupplierPriceGoodsService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 供应报价与商品关联表(SupplierPriceGoods)表服务实现类
 *
 * @author makejava
 * @since 2024-10-21 10:20:42
 */
@Service("supplierPriceGoodsService")
public class SupplierPriceGoodsServiceImpl implements SupplierPriceGoodsService {
    @Resource
    private SupplierPriceGoodsDao supplierPriceGoodsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SupplierPriceGoods queryById(Integer id) {
        return this.supplierPriceGoodsDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param supplierPriceGoods 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<SupplierPriceGoods> queryByPage(SupplierPriceGoods supplierPriceGoods, PageRequest pageRequest) {
        long total = this.supplierPriceGoodsDao.count(supplierPriceGoods);
        return new PageImpl<>(this.supplierPriceGoodsDao.queryAllByLimit(supplierPriceGoods, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param supplierPriceGoods 实例对象
     * @return 实例对象
     */
    @Override
    public SupplierPriceGoods insert(SupplierPriceGoods supplierPriceGoods) {
        this.supplierPriceGoodsDao.insert(supplierPriceGoods);
        return supplierPriceGoods;
    }

    /**
     * 修改数据
     *
     * @param supplierPriceGoods 实例对象
     * @return 实例对象
     */
    @Override
    public SupplierPriceGoods update(SupplierPriceGoods supplierPriceGoods) {
        this.supplierPriceGoodsDao.update(supplierPriceGoods);
        return this.queryById(supplierPriceGoods.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.supplierPriceGoodsDao.deleteById(id) > 0;
    }
}
